import { ESGltfModel, ESJEditingMode } from "earthsdk3";
import { ElMessage } from "element-plus";
import { PartialWithUndefinedReactivePropsToNativeProps, ReactivePropsToNativePropsAndChanged, SceneObjectKey, extendClassProps, reactJson } from "earthsdk3";

/**
 * 测试 rts使用的模型
 */
export class ESRtsFeatureAdding extends ESGltfModel {
    static override readonly type = this.register('ESRtsFeatureAdding', this, { chsName: 'rts使用的模型', tags: ['ESObjects', '_ES_Impl_Cesium', '_ES_Impl_UE'], description: "地理多边形体" });
    override get typeName() { return 'ESRtsFeatureAdding'; }
    override get defaultProps() { return ESRtsFeatureAdding.createDefaultProps(); }
    override get json() {
        return {
            // @ts-ignore
            ...this._innerGetJson(),
            "show": this.show,
            "materials": this.materials,
            "rotation": this.rotation,
        } as JsonType;
    }
    override set json(value: JsonType) { this._innerSetJson(value); }
    static override supportEditingModes = [
        ...ESGltfModel.supportEditingModes,
        ESJEditingMode.Translation,
        ESJEditingMode.Rotation,
    ];
    override updateEditing() {
        // if (this.editing) {
        //     const editingModes: string[] = [];
        //     do {
        //         if (this.editingBindMode == 'singlePoint') {
        //             editingModes.push(ESJEditingMode.Translation, ESJEditingMode.Rotation);
        //             break;
        //         }
        //     } while (false);

        this.activeViewer?.startEditing(this, [ESJEditingMode.Translation, ESJEditingMode.Rotation], { callSource: "inner" });
        // }
    }

    constructor(id?: SceneObjectKey) {
        super(id);
        // this.show = false
        {
            let message: any
            const updata = () => {
                if (this.editing) {
                    message = ElMessage({
                        message: '1. 双击鼠标左键或点击ESC键退出编辑2. 点击空格键进行平移、旋转编辑方式的切换',
                        duration: 0,
                        plain: true,
                    })
                } else {
                    message && message.close()
                }
            }
            this.dispose(this.editingChanged.disposableOn(updata))
            this.dispose(() => message && message.close())
        }
    }
    override getESProperties() {
        const properties = { ...super.getESProperties() };
        return {
            ...properties,
            coordinate: [
                ...properties.coordinate,
            ]
        };
    };
    override getProperties(language: string) {
        return [
            ...super.getProperties(language),
        ];
    }
}

export namespace ESRtsFeatureAdding {
    export const createDefaultProps = () => ({
        ...ESGltfModel.createDefaultProps(),
        datasetName: undefined as string | undefined,
        featureClassId: undefined as string | undefined,
        tileServiceName: undefined as string | undefined,
        materials: reactJson<any>({}),
        geometryId: undefined as string | undefined,
    });
}
extendClassProps(ESRtsFeatureAdding.prototype, ESRtsFeatureAdding.createDefaultProps);
export interface ESRtsFeatureAdding extends ReactivePropsToNativePropsAndChanged<ReturnType<typeof ESRtsFeatureAdding.createDefaultProps>> { }
type JsonType = PartialWithUndefinedReactivePropsToNativeProps<ReturnType<typeof ESRtsFeatureAdding.createDefaultProps> & { type: string }>;